function [cost, goodNum] = p2epoch(n,m,parm,p)
f = 300;
t = 20;
d = 3000;
k = 1200;
p1 = 0.01;
p2 = 0.75;
e = 1500;

cutterX = round(wblrnd(parm(1), parm(2)));
nonCutterX = geornd(p);
X = min([cutterX, nonCutterX]);
if m > X
    product = [randsrc(X,1,[0 1;p1 (1-p1)]); randsrc(m-X, 1, [0 1;p2 (1-p2)])];
else
    product = randsrc(X,1,[0 1;p1 (1-p1)]);
end

%faultNum = 0;
%goodNum = 0;
checkNum = 0;
cost = 0;
maxCheckNum = floor(m / n);
%checkPoint = n;
for i = n:n:n*maxCheckNum
    checkNum = checkNum + 1;
    if product(i) == 0
        if i <= X
            cost = cost + e;
        else
            cost = cost + d + sum(product(1:i)==0) * f + checkNum * t;
            goodNum = sum(product(1:i)==1);
            return
        end
    end
end

goodNum = sum(product(1:m)==1);
if m <= X
    cost = cost + k + sum(product(1:m)==0) * f + checkNum * t;
else
    cost = cost + d + sum(product(1:m)==0) * f + checkNum * t;
end


end